/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interpreter;

import ast.AST;

/**
 *
 * @author Stephen
 */
public class SubtractionOperator {
    private AST t;
    private InterpreterVisitor iv;

    public SubtractionOperator(AST t, InterpreterVisitor iv) {
        this.t = t;
        this.iv = iv;
    }

    public Object execute() {
        Object operand1 = t.getKid(1).accept(iv);
        Object operand2 = t.getKid(2).accept(iv);
        String type = InterpreterVisitor.parseType((String) operand1);

        if (type.equalsIgnoreCase("float")) {
            float result = Float.parseFloat((String) operand1) - Float.parseFloat((String) operand2);
            return Float.toString(result);
        } else if (type.equalsIgnoreCase("int")) {
            int result = Integer.parseInt((String) operand1) - Integer.parseInt((String) operand2);
            return Integer.toString(result);
        }
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
